package com.example.controller;

import com.example.result.Result;
import com.example.entity.Buyer;
import com.example.service.BuyerService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/buyer")
@Tag(name="买家信息相关接口")
public class BuyerController {
    @Resource
    private BuyerService buyerService;

    //1.    查询id/buyer/selectById/1
    @GetMapping("/selectById/{id}")
    @Operation(summary = "根据id查询用户信息",description="根据id查询用户信息")
    public Result selectById(@PathVariable Integer id){
        Buyer buyer = buyerService.selectById(id);
        return Result.success(buyer);
    }

    //4. 分页查询 *pageNum:当前页码 *pageSize:每页的个数
    //引入pagehelper
    @Operation(summary = "分页查询所有用户信息",description="分页查询所有用户信息")
    @GetMapping("/selectPage")
    public Result selectPage (Buyer buyer,
                              @RequestParam (defaultValue = "1") Integer pageNum ,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Buyer> pageInfo= buyerService.selectPage(buyer,pageNum,pageSize) ;
        return Result.success(pageInfo);
    }

    //    5.查询所有数据/buyer/selectAll
    @Operation(summary = "查询所有用户信息",description="查询所有用户信息，不包含分页数据")
    @GetMapping("/selectAll")
    public Result<List<Buyer>> selectAll(Buyer buyer){
        List<Buyer> list = buyerService.selectAll(buyer);
        return Result.success(list);
    }


}
